package com.xingshentech.ugv.operate.sdk;

import android.content.Context;
import android.widget.TextView;

import com.xingshentech.ugv.operate.R;
import com.xingshentech.ugv.operate.base.CommonRecyclerAdapter;
import com.xingshentech.ugv.operate.module.bean.UserPwdBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.xingshentech.ugv.operate.module.utils.CommonAdapterKt;
import com.xingshentech.ugv.operate.widget.CommonPopWindow;

import java.util.List;

public class UserPwdAdapter extends CommonRecyclerAdapter<UserPwdBean> {
    Context mContext;
    List<UserPwdBean> datas;
    CommonPopWindow commonPopWindow;

    public UserPwdAdapter(Context context, List<UserPwdBean> datas) {
        super(R.layout.item_user_pwd, datas);
        this.mContext = context;
        this.datas = datas;
    }

    @Override
    public void convert(BaseViewHolder holder, final UserPwdBean userPwdBean) {
        int position = CommonAdapterKt.getAdapterPosition(holder);
        TextView tv_user = holder.getView(R.id.tv_user);
        TextView tv_pwd = holder.getView(R.id.tv_pwd);
        TextView iv_delete = holder.getView(R.id.iv_delete);
        tv_user.setText(userPwdBean.getUsername());
        tv_pwd.setText(userPwdBean.getPassword());
        holder.getView(R.id.iv_delete).setOnClickListener(v -> {
            datas.remove(position);
            notifyDataSetChanged();
        });
        TextView et_userName = holder.getView(R.id.et_userName);
        TextView et_password = holder.getView(R.id.et_password);
        holder.getView(R.id.item_parent).setOnClickListener(v -> {
            et_userName.setText(userPwdBean.getUsername());
            et_password.setText(userPwdBean.getPassword());
            commonPopWindow.dismiss();
        });
    }
}

